<template>
    <bi-form-item label="可以管理的文章">
        <bi-radio v-model="form.adminArticlePart" :option="adminArticlePartOption" :disabled="disabled"  ></bi-radio>
    </bi-form-item>
    <bi-form-item label="设置可管理文章的栏目" v-if="form.adminArticlePart=='custom'">
         <bi-list :data="form.adminArticlePartList"  v-slot="row"  type="border" dir="row" :disabled="disabled"  @add="addPart" @del="delPart"  >
            {{row.item.title}}
        </bi-list>
    </bi-form-item>
</template>
<script>
import powerExtendMixin from  '@@/admin/assets/js/powerExtendMixin.js';
import addPartDialog from 'add-part-dialog.vue';
export default {
    mixins:[powerExtendMixin],
    data(){
 
        let disabled = true;

        if (this.$user.super) disabled = false;
        if (this.userData && this.userData.adminArticlePart && this.userData.adminArticlePart=='all') disabled = false;

        let adminArticlePartOption = [
            {value:'all',disabled,label:'全部栏目的文章'},
            {value:'custom',label:'指定栏目的文章'},
        ]

        let form = {
            adminArticlePart:'custom',
            adminArticlePartList:[]
        }

        return {
            adminArticlePartOption,
            form
        }
    },
    watch:{
        
    },
    methods:{
        addPart(){

            let hasList = [];

            for(let i=0;i<this.form.adminArticlePartList.length;i++){
                hasList.push(this.form.adminArticlePartList[i].part_id);
            }

            this.$dialog({
                type:'vue',
                content:admin.createApp(addPartDialog,{hasList}),
                callback:(re)=>{
                    if (re.part_id){
                        this.form.adminArticlePartList.push(re);
                    }
                }
            })
        },
        delPart(index,item){
            this.$confirm('确定要删除['+item.title+']吗',(re)=>{
                if (re){
                    this.form.adminArticlePartList.splice(index,1);
                }
            });
        }
    }
}
</script>